#pragma once
#include "widgets.h"

#include <QWidget>
class S_WIDGETS_EXPORT SCheckEx : public QWidget
{
	Q_OBJECT
public:
	enum class SelectType
	{
		Check,
		Radio,
		Switch
	};

	SCheckEx(const QString& ,QWidget* parent = nullptr);
	~SCheckEx() = default;

	void setSelectType(SelectType v) { m_type = v; }
	void setIndex(int v) { m_index = v; }
	int index() const { return m_index; }
	bool isSelected() {
		return m_selectState != Qt::Unchecked;
	}
	void setSelectState(Qt::CheckState v, bool notify = false);

	virtual QSize sizeHint() const override;

Q_SIGNALS:
	void stateChanged(int);

protected:
	virtual void mousePressEvent(QMouseEvent*) override;
	virtual void enterEvent(QEvent* event) override;
	virtual void leaveEvent(QEvent* event) override;
	virtual void paintEvent(QPaintEvent* event) override;

private:
	SelectType	m_type = SelectType::Check;
	QString		m_text;
	int			m_index = 0;
	Qt::CheckState m_selectState = Qt::Unchecked;
	bool		m_hover = false;
};

class S_WIDGETS_EXPORT SRadioGroup : public QObject
{
	Q_OBJECT
public:
	SRadioGroup(QObject* p);

	void addRadio(SCheckEx*);

protected Q_SLOTS :
	void onRadioSelect(int);

private:
	std::map<int, SCheckEx*>	m_items;
};